﻿using Google.Apis.Tasks.v1.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace G_Tasks
{
    public partial class AddTaskForm : Form
    {
        TasksTabPage tab;
        NoteItem note;
        public AddTaskForm(TasksTabPage tab, NoteItem note = null)
        {
            InitializeComponent();

            this.tab = tab;
            this.note = note;
            if (note != null)
            {
                textBox1.Text = note.NoteText;
                if (note.NoteDue != DateTime.MaxValue)
                {
                    dateTimePicker1.Checked = true;
                    dateTimePicker1.Value = note.NoteDue;
                }
            }
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            if (note == null)
                note = new NoteItem(new Task());

            note.NoteText = textBox1.Text;
            if (dateTimePicker1.Checked)
                note.NoteDue = dateTimePicker1.Value;
            else
                note.NoteDue = DateTime.MaxValue;
            
            note.SubmitChanges();

            if (note.RelatedTask.Id == null)
                tab.AddNote(note);

            tab.ClientSync();

            this.Close();
        }
    }
}
